Public Class GenerarValeDeMP
    Dim RNGenerarVMP As New RNCono.ValesDeMateriaPrima
    Dim DT As New DataTable


    Private Sub GenerarValeDeMP_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ActualizarGrilla()
    End Sub

    Private Sub txtCantidad_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCantidad.KeyPress
        If Char.IsNumber(e.KeyChar) Then
            e.Handled = False
        ElseIf Char.IsControl(e.KeyChar) Then
            e.Handled = False
        Else
            e.Handled = True
        End If
    End Sub

    Private Sub cmdAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAceptar.Click
        MsgBox(RNGenerarVMP.InsertarVale(1, DT.Rows(dgvSolicitudes.SelectedCells(0).RowIndex)("Codigo"), Val(txtCantidad.Text)))
        ActualizarGrilla()
    End Sub

    Private Sub txtCantidad_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCantidad.TextChanged
        Dim Cantidad As Long = 0
        Dim Restante As Long = 0
        Dim Disponible As Long = 0
        Restante = DT.Rows(dgvSolicitudes.SelectedCells(0).RowIndex)("Pendiente de generar")
        Disponible = DT.Rows(dgvSolicitudes.SelectedCells(0).RowIndex)("Disponible en silo")
        Cantidad = Val(txtCantidad.Text)

        If Cantidad <= Restante And Cantidad <= Disponible And Cantidad >= 50 Then
            cmdAceptar.Enabled = True
        Else
            cmdAceptar.Enabled = False
        End If
    End Sub

    Private Sub ActualizarGrilla()
        DT = RNGenerarVMP.ObtenerSolicitudesPendientes
        dgvSolicitudes.DataSource = DT
    End Sub

    Private Sub cmdCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancelar.Click
        Me.Dispose()
    End Sub
End Class